#include <bits/stdc++.h>
using namespace std;
int main() {
  // O(n^2)
  // leetcode   A+B == C
  // find A(x + C)  count
  // find B(x - C)  count
  // key -> value
  // value ++;
  // unordered_map  O(1)
  int n, c;
  cin >> n >> c;
  unordered_map<int, int> ump;
  long long ans = 0;
  while (n--) {
    int x;
    cin >> x;
    ans += ump[x + c];
    ans += ump[x - c];
    ump[x]++;
  }
  cout << ans << endl;
}